var Scroll = {};
//自调用函数
(function(win,doc,$){
   function CusScroollBar(options){
  			this._init(options);
  	};
  	$.extend(CusScroollBar.prototype,{
  		_init:function(options){
  			var self = this
  			self.options = {
  				scrollDir:"y",  // 滚动方向
				contSeletor:"",  // 滚动内容区选择器		
  				barSelector:"",  // 滚动条选择器
  				sliderSelector:"",  // 滚动滑动儿选择器
  			}
  			$.extend(true, self.options, options|| {});
  			self._initDomEvent();
  			return self;
  		},
  		/*初始化DOM引用*/
  		_initDomEvent:function(){
  			//console.log(self)
  			var opts = this.options;
  			console.log(opts)
  			//滚动内容区对象，必填项 
  			this.$cont = $(opts.contSeletor);
  			//滚动条滑块对象，必填项
			this.$slider = $(opts.sliderSelector);
			//滚动条对象
			this.$bar = opts.barSelector ? $(opts.barSelector):self.$slider.parent();
			//获取文档对象
			this.$doc = $(doc);	
			this._initSliderDragEvent()
  		},
  		/*
		初始化滑块拖动功能
		@return {[Object]} [this]
    	 */
    	_initSliderDragEvent:function(){
					var self =this;  //this层层传递 始终是CusScrollBar这个对象
					console.log(this);
					var slider = this.$slider,
						sliderEl = slider[0];						
					if(sliderEl){
						var doc = this.$doc,
							dragStartPagePosition,
							dragStartScrollPosition,
							dragContBarRate;
					function mousemoveHandler(e){
						e.preventDefault();
						console.log("mousemove");
						if(dragStartPagePosition== null){ 
							return;		//说明没有在滑块上按下鼠标
						}
						
						//e.pageY - dragStartPagePosition为滑块移动距离
						//scrollTo(内容的滚动高度)
					}
					
					slider.on("mousedown",function(e){  //e是事件对象(jquery包装后的)
							e.preventDefault();  //阻止事件默认行为
							console.log("mousedown");
			
								
							doc.on("mousemove.scroll",
								mousemoveHandler
							).on("mouseup.scroll",function(e){
								console.log("mouseup");
								doc.off(".scroll")  //.scroll为上面绑定的命名空间 相当于off("mousemove mouseup")
							});
					});
					}
					return self;
				}, 	
  	});
  	
  	// CusScroollBar._init = function(){
  	// 		console.log('test')
  	// }
  	win.CusScroollBar = CusScroollBar
})(window,document,jQuery);
var obj = {
	contSeletor:".scroll-wrap",  // 滚动内容区选择器		
	barSelector:".scroll-bar",  // 滚动条选择器
	sliderSelector:".scroll-slider",  // 滚动滑动儿选择器
}
var a  = new CusScroollBar(obj)
